11 In-Class work
11.1 1) Show a map outline of Iowa and Illinois (similar to Minnesota map upstream)
IAandIL <- states %>%
filter(name %in% c('Iowa', 'Illinois')) %>%
st_transform(2163)
mapview(IAandIL)11.2 2) Subset LAGOS data to these sites, how many sites are in Illinois and Iowa combined? How does this compare to Minnesota?
#Subset lakes based on spatial position
IAandIL_lakes <- spatial_lakes[IAandIL,]
nrow(IAandIL_lakes)## [1] 16466
nrow(minnesota_lakes)## [1] 29038
Illinois and Iowa have 16,466 sites. Minnesota has 29,038 sites. This is nearly double the number of sites, compared to Illinois and Iowa combined.
11.3 3) What is the distribution of lake size in Iowa vs. Minnesota?
- Here I want to see a histogram plot with lake size on x-axis and frequency on y axis (check out geom_histogram)
- make histogram log
iowa <- states %>%
filter(name == 'Iowa') %>%
st_transform(2163)
iowa_lakes <- spatial_lakes[iowa,]
iowa_lakes$state <- 'Iowa'
minnesota_lakes$state <- 'Minnesota'
IAandMN_lakes <- bind_rows(iowa_lakes, minnesota_lakes)
names(IAandMN_lakes)## [1] "lagoslakeid" "nhdid" "gnis_name"
## [4] "lake_area_ha" "lake_perim_meters" "nhd_fcode"
## [7] "nhd_ftype" "iws_zoneid" "hu4_zoneid"
## [10] "hu6_zoneid" "hu8_zoneid" "hu12_zoneid"
## [13] "edu_zoneid" "county_zoneid" "state_zoneid"
## [16] "elevation_m" "state" "geometry"
ggplot(IAandMN_lakes) + aes(x=lake_area_ha, fill = state) +geom_histogram()+ scale_x_log10() + ylab('Frequency') +xlab('Lake Size in Hectares') + facet_wrap(vars(state))## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

There are more lakes in Minnesota than in Iowa, but the distribution of lakes is similar. For both states there are a greater number of smaller lakes, and a smaller number of large lakes.
11.4 4) Make an interactive plot of lakes in Iowa and Illinois and color them by lake area in hectares
mapview(IAandIL_lakes, zcol = "lake_area_ha", at = c(0, 5, 10, 100, 250, 500, 750, 1000, 5000, 10000))